package servlets;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.naming.NamingException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import parser.ParserXML;
import BDs.FacadeBusinessDelegate;
import entitiesdto.CantidadMateriaPrimaDTO;


 public class EnvioProveedoresSVL extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
   static final long serialVersionUID = 1L;
   
 
	public EnvioProveedoresSVL() {
		super();
	}   	
	

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
	}  	
	

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		HttpSession session = request.getSession(true);
		String path = request.getParameter("patharchivo");
		
		List<CantidadMateriaPrimaDTO> cmpList = new ArrayList<CantidadMateriaPrimaDTO>();
		
		if (path != null) {
			ParserXML parser = new ParserXML();
			File archivo = new File(path);
			cmpList = parser.recibirEnvioProveedores(archivo);
			if (cmpList != null) {
					try {
						FacadeBusinessDelegate.getInstance().recibirProvedores(cmpList);
					} catch (NamingException e) {
						e.printStackTrace();
					}
			}
		}

		session.setAttribute("listaCmpParseada", cmpList);
		
		RequestDispatcher dispatcher = request.getRequestDispatcher("/enviarProveedores.jsp");
		dispatcher.forward(request, response);
	}   	  	    
}